//
//  XMCommonSetttingController.m
//  XMWeibo
//
//  Created by chi on 14-9-2.
//  Copyright (c) 2014年 xiaoming. All rights reserved.
//

#import "XMCommonSetttingController.h"

#import "MBProgressHUD+XM.h"


#import "XMReadModeController.h"
#import "XMFontSizeController.h"
#import "XMPicQualityController.h"
#import "XMLanguageController.h"

@interface XMCommonSetttingController ()

@end

@implementation XMCommonSetttingController


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // 添加分组
    [self setupGroup1];
    [self setupGroup2];
    [self setupGroup3];
    [self setupGroup4];
    [self setupGroup5];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.tableView reloadData];
}


#pragma mark - 添加分组

- (void)setupGroup1
{
    XMGroupInfo *group1 = [self addGroup];
    
    XMLabelSettingItem *readMode = [XMLabelSettingItem arrowCellItemWithTitle:@"阅读模式" subTitle:nil icon:nil class:[XMReadModeController class]];
    readMode.defaultText = @"无图模式";
    readMode.readyForVc = ^(XMLabelSettingItem *item, XMCheckController *controller) {
        controller.source = item;
    };
    
    XMLabelSettingItem *fontSize = [XMLabelSettingItem arrowCellItemWithTitle:@"字体大小" subTitle:nil icon:nil class:[XMFontSizeController class]];
    fontSize.defaultText = @"大";
    fontSize.readyForVc = ^(XMLabelSettingItem *item, XMCheckController *controller) {
        controller.source = item;
    };
    
    XMBaseSettingItem *showRemark = [XMSwitchSettingItem cellItemWithTitle:@"显示备注" subTitle:nil icon:nil];
    
    group1.cellItems = @[readMode, fontSize, showRemark];
}

- (void)setupGroup2
{
    XMGroupInfo *group2 = [self addGroup];
    
    XMArrowSettingItem *picQuality = [XMArrowSettingItem arrowCellItemWithTitle:@"图片质量设置" subTitle:nil icon:nil class:[XMPicQualityController class]];
    
    group2.cellItems = @[picQuality];
}


- (void)setupGroup3
{
    XMGroupInfo *group3 = [self addGroup];
    
    XMBaseSettingItem *voice = [XMSwitchSettingItem cellItemWithTitle:@"声音" subTitle:nil icon:nil];
    
    group3.cellItems = @[voice];
}

- (void)setupGroup4
{
    XMGroupInfo *group1 = [self addGroup];
    
    XMLabelSettingItem *language = [XMLabelSettingItem arrowCellItemWithTitle:@"多语言环境" subTitle:nil icon:nil  class:[XMLanguageController class]];

    language.defaultText = @"跟随系统";
    language.readyForVc = ^(XMLabelSettingItem *item, XMCheckController *controller) {
        controller.source = item;
    };
    
    
    group1.cellItems = @[language];
}

- (void)setupGroup5
{
    XMGroupInfo *group5 = [self addGroup];
    
    XMBaseSettingItem *clearPic = [XMBaseSettingItem cellItemWithTitle:@"清空图片缓存" subTitle:nil icon:nil];
    clearPic.operationBlock = ^{
        [MBProgressHUD showSuccess:@"清除图片成功"];
    };
    
   XMBaseSettingItem *clearSearch = [XMBaseSettingItem cellItemWithTitle:@"清空搜索历史" subTitle:nil icon:nil ];
    clearSearch.operationBlock = ^{
        [MBProgressHUD showSuccess:@"清除搜索历史成功"];
    };
    
    group5.cellItems = @[clearPic, clearSearch];
}

@end
